package com.seed.core.pojo.seed;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.seed.core.annotation.HasMany;

import java.util.HashMap;
import java.util.Map;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class HasManys extends HasOnes {
    protected Integer limit = 5;

//    public HasManys of(Class<?> selfEntityClass, Class<?> targetEntityClass, HasMany hasMany) {
//        setExtraType(hasMany.extraType());
//        setSelfEntityClass(selfEntityClass);
//        setTargetEntityClass(targetEntityClass);
//        setSelfColumn(hasMany.selfColumn());
//        setTargetColumn(hasMany.targetColumn());
//        setLabel(hasMany.label());
//        setComment(hasMany.comment());
//        setCascade(hasMany.cascade());
//        setLimit(hasMany.limit());
//        setExtra(hasMany.extra());
//
//        return this;
//    }

    public HasOnes of2(Map<Class<?>, Seed> seeds, Class<?> selfEntityClass, Class<?> targetEntityClass, HasMany hasMany) {
        setSelfSeed(seeds.get(selfEntityClass));
        setTargetSeed(seeds.get(targetEntityClass));
        setTargetSeedName(targetSeed.getName());

        setSelfEntityClass(selfEntityClass);
        setTargetEntityClass(targetEntityClass);

        setSelfColumn(hasMany.selfColumn());
        setTargetColumn(hasMany.targetColumn());
        setLabel(hasMany.label());
        setComment(hasMany.comment());

        setExtra(hasMany.extra());

        setCascade(hasMany.cascade());
        setLimit(hasMany.limit());

        return this;
    }

    public HasManys clone() {
        HasManys ret = new HasManys();
        ret.setTargetSeedName(targetSeedName);
        ret.setSelfSeed(selfSeed);
        ret.setTargetSeed(targetSeed);
        ret.setSelfEntityClass(selfEntityClass);
        ret.setTargetEntityClass(targetEntityClass);
        ret.setSelfColumn(selfColumn);
        ret.setTargetColumn(targetColumn);
        ret.setLabel(label);
        ret.setComment(comment);

        if(extra != null) ret.setExtra(new HashMap<>(extra));

        ret.setCascade(cascade);
        ret.setLimit(limit);

        return ret;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }
}
